<%--
    fileName      : /apphomeoption/ctpcfshomeo.jsp
    author        : user
    createDate    : 2016-12-16  
    lastModifier  : user
    lastModifyDate: 2016-12-16       
    description   : 列表页面
--%>
<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' %>
<%@ taglib uri='ctp-tag' prefix='ctp' %>
<%@ page import="com.icbc.cte.base.CTEConstance"%>
<%
	String file_visit_path = "";
	String file_save_path = "";
	try {
		file_visit_path = CTEConstance
				.getEnvProperty("file_visit_path");
		file_save_path = CTEConstance.getEnvProperty("file_save_path");
	} catch (Exception e) {
		file_visit_path = "";
		file_save_path = "";
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title></title>

        <ctp:include items='public,ajaxfileupload,grid,validator,borderlayout,panel,form,button,groupbox,gridlayout,label,textfield,combobox,link,checkboxgroup,checkbox,textarea,datepicker,checkbox,chain,message_ex,ajaxtree'/>

        <script type='text/javascript' kind='variant'>

            var borderlayout1;
            var queryPanel;
            var queryForm;
            var queryGroupbox;    //问题信息
            var queryGridlayout;     
            var id; //资讯id
            var homeId; //资讯项父类ID
            var imageUrl; //资讯图片地址
            var title; //资讯标题
            var content; //资讯内容
            var updateTime; //资讯时间
            var url; //资讯链接地址
            
            var validator5;
            var goBack;		      //返回
            var submit;		      //提交
            var reset;	     	  //重置
            var modify;
            var modifyURL='';
            var flag;			  //新增修改标识
            var v_ctpcfshomeoId = "";
        </script>
        <script type='text/javascript' kind='event'>
	        /*
	         * @method initData
	         * @desc  初始化数据
	         * @author user
	         */
			function initData(){
				setReadOnly(false);
				if(flag == 0){//新增
					queryForm.getObj("imageUrl").setReadOnly(true);
					queryPanel.setTitle('<ctp:label key="add"/>');
				}else if(flag == 1){//修改
					queryForm.getObj("imageUrl").setReadOnly(true);
					modifyURL = '<ctp:url href="ctpcfshomeoptionmain.flowc" flowActionName="queryctpcfshomeodetail"/>';
					queryPanel.setTitle('<ctp:label key="modify"/>');
					   ctp.data.getJSONA({
							url:modifyURL,
							reqData:{"language":"zh_CN","id":v_ctpcfshomeoId},
							success:function(data){
								modifyData = data;
								v_ctpcfshomeoId = modifyData.id;
								if(modifyData && modifyData.retCode == "0"){
									setValue('0');
								}
							}
					});
				}else{  //查看
					queryForm.getObj("submit").hide();
					queryForm.getObj("reset").hide();
					setReadOnly(true);
					queryPanel.setTitle('<ctp:label key="view"/>');
				}
			}

			/*
	         * @method setReadOnly
	         * @desc  设置表单内容是否readonly
	         * @author user
	         */
			function setReadOnly(isReadOnly){
			    queryForm.getObj("id").setReadOnly(isReadOnly);
			    queryForm.getObj("homeId").setReadOnly(isReadOnly);
			    queryForm.getObj("imageUrl").setReadOnly(isReadOnly);
			    queryForm.getObj("title").setReadOnly(isReadOnly);
			    queryForm.getObj("content").setReadOnly(isReadOnly);
			    queryForm.getObj("url").setReadOnly(isReadOnly);
			}

			/*
	         * @method formSucc
	         * @desc  表单提交成功回调函数--提示成功返回列表页面。
	         * @author user
	         */
			function formSucc(data){
				  var _message;  
				  if(flag=="0"){ 
					_message='<ctp:label key="add"/>';//新增
				  }else if(flag=="1") {
					_message='<ctp:label key="modify"/>';//修改
				  }  

				  if(data[0].retCode=="0"){//提交成功
					  var mailTo = '';
					  var smtpcontent = '';
					  var subject = '';
					  if(flag == '0'){
						  ctpMSB.confirm({
							  title: '<ctp:label key="tips_msg"/>',
							  message: _message+'<ctp:label key="success_continue_add"/>',
							  cancelTxt: '<ctp:label key="back2list"/>',
							  handler: function(tp){
								  if(tp == 'ok'){
									  window.location.href="<ctp:url href='ctpcfshomeoptionmain.flowc' flowActionName='ctpcfshomeodetail'/>&flag=0";
								  }else{
									   history.go(-1);
								  }
						      }
						  })
					  }else if(flag == '1'){
	                   ctpMSB.succeed({
	                       title:'<ctp:label key="tips_msg"/>',
	                       closeBtn:true,
	                       message:_message+'<ctp:label key="success"/>',
	                       handler:function(){
								try{
									top.ctpTAB.delTab(top.ctpTAB.getCurrentTabPos());
								}catch(e){
									
								}
						   }
	                       });//操作成功！
					  }
	                 }else{
	              		 var msgErr='<ctp:label key="error_code"/>'+data[0].errorCode+'<ctp:label key="error_msg"/>'+data[0].errorMsg;              
	                     ctpMSB.error({
	                        title:'<ctp:label key="error"/>',
	                        message:_message+''+ msgErr
	                     });//操作失败！
	                }                     
			}
			
			/*
	         * @method submitForm
	         * @desc  提交表单
	         * @author user
	         */
			function submitForm(){
				 var _mContext = "prodetail.jsp -> queryFormSubmit()";
	        	 try {
	            	 if(flag == 0){
	    		        queryForm.setHiddenValue("flowActionName","addctpcfshomeo");
	               	 }else if(flag == 1){
	               		queryForm.setHiddenValue("flowActionName","editctpcfshomeo");
	                 }
	               		queryForm.submit();
	        	 }
	        	 catch (e) {
	                 ctp.core.log.err(_mContext, e.message);
	             }
			}
			/*
	         * @method resetForm
	         * @desc  重置表单
	         * @author user
	         */
			function resetForm(){
				ctp.util.closeAllPrompt();//关掉页面上所有验证框架产生的提示框
				if(flag == 0){//新增
					queryForm.reset();
				}else if(flag == 1){//修改
					setValue('1');
				}
			}

			/*
	         * @method setValue
	         * @desc  设置页面值
	         * @author user
	         */
			function setValue(isReset){
			
                if(isReset == '1'){
					queryForm.reset();
				}
				
                queryForm.getObj("id").setValue(modifyData.id);
                queryForm.getObj("homeId").setValue(modifyData.homeId);
                queryForm.getObj("imageUrl").setValue(modifyData.imageUrl);
                
                queryForm.getObj("title").setValue(modifyData.title);
                queryForm.getObj("content").setValue(modifyData.content);
                queryForm.getObj("url").setValue(modifyData.url);
			}
			/*
	         * @method goBack
	         * @desc 点击返回按钮
	         * @author user
	         */
			function goBack(){
				history.go(-1);
			}
						
        </script>
		<script type='text/javascript' kind='notUI'>
			var formValidator = new ctp.validator({id:"formValidator"
        	});//验证框架
		</script>
        <script type='text/javascript' kind='ui'>

            $(window).load(function(){
            	v_ctpcfshomeoId = '<ctp:out name="id"/>';
            	flag = '<ctp:out name="flag"/>';
   		     //================================UI变量定义片段============================================================
                

						id = new ctp.ui.textfield ({//资讯id
							id : 'id' ,
							width:'180px',
							type : 'hidden'
						});	
						/*
						homeId = new ctp.ui.textfield ({//资讯项父类ID
							id : 'homeId' ,
							beanName:'ctpcfshomeo',
							width:'180px',
							type : 'text'
						});*/	

						homeId = new ctp.ui.combobox ({//类别
							id : 'homeId' ,
							width:'180px',
							defaultItems:[{
						     	text:'---请选择---',
						     	value:'',
						     	selected:'true'
					     	}],
					     	remote: {
								url: '<ctp:url href="ctpcfshomeoptionmain.flowc" flowActionName="gethomeidlist" />'
							}
							/*
							items:[
								{text:'是',value:'1',title:'是'},
								{text:'否',value:'0',title:'否'}
							]*/
						});	
					
						imageUrl = new ctp.ui.textfield ({//资讯图片地址
							id : 'imageUrl' ,
							width:'180px',
							type : 'text'
						});	

						var	ajaxfileup = new ctp.ui.ajaxfileupload( {
							id :'fileuploadId',
							auto :false,
							height :'50px', //高度固定
							width:'180px', 
							
						//	height: 'auto', //高度自适应
						//	browserBtntext :'<ctp:label key="ajaxfileup.browserBtntext" />',
							multi :false,
							fileExt : '*.JPG;*.JPEG;*.PNG;*.jpg;*.jpeg;*.png',
							uploadBtn :true,
							clearBtn :true,
							flowcUrl :'<ctp:url href="upload/fileupload.flowc" />',
							flowActionName :'addfile',

							onComplete: function(fileID, fileObj, response, data){
								//jQuery("#xdiv").append(fileID+"..."+JSON.stringify(fileObj)+"..."+JSON.stringify(data)+"..."+JSON.stringify(response));
								var tempjson = eval('(' + response + ')');
								
								if (tempjson[0].retCode != '0') {//如果上传失败
									ctpMSB.alert({
										message: '<ctp:label key="ajaxfileup.uploadError" />',
										title: '<ctp:label key="tips_msg" />',
										btn: [['<ctp:label key="confirm" />', 'OK']],
										closeBtn: false
									});
								}
								else {//上传成功		
							     	queryForm.getObj("imageUrl").setValue("<%=file_visit_path%>"+tempjson[0].relFileName);
									document.queryForm.filePath.value="<%=file_save_path%>"+tempjson[0].relFileName;
									document.queryForm.fileName.value=tempjson[0].relFileName; 
								    ctpMSB.alert({
			                      		title: '信息提示',
			                      		message:"上传文件成功"
		                 			});
															
								}
							}
							
						});                            
					
						title = new ctp.ui.textfield ({//资讯标题
							id : 'title' ,
							width:'180px',
							type : 'text'
						});	
					
						content = new ctp.ui.textfield ({//资讯内容
							id : 'content' ,
							width:'180px',
							type : 'text'
						});	
					
						url = new ctp.ui.textfield ({//资讯链接地址
							id : 'url' ,
							width:'180px',
							type : 'text'
						});	
										                                

                 queryGridlayout = new ctp.ui.gridlayout({
                     id: 'queryGridlayout',
                     width: '850px',
                     align: 'center',
                     defaults:{
             			align: 'center',
             			label: {width: '100px'},
            			element:{
            				//默认创建textfield组件
            				type: 'textfield',
            				//默认的组件自带属性,width设成'100%'或不传，则该组件和关联标签的宽度之和会占满所在的列
            				options:{width: '120px'}
            			}
                         			
             		 },
                                  
                     items: [
                               [                                  {
                                label: {
                                    id: 'label0', 
                                    text: '', 
                                    width: '100px'
                                }, 
                                element: id
                        }],[                                 {
                                label: {
                                    id: 'label1', 
                                    text: '<ctp:label key="homeId"/>', 
                                    width: '100px'
                                }, 
                                element: homeId,
                                colspan: 2
                        }],[                                  {
                            label: {
                                id: 'label3', 
                                text: '<ctp:label key="title"/>', 
                                width: '100px'
                            }, 
                            element: title,
                            colspan: 2
                    }],[                                  {
                            label: {
                                id: 'label4', 
                                text: '<ctp:label key="content"/>', 
                                width: '100px'
                            }, 
                            element: content,
                            colspan: 2
                    }],[                                  {
                                label: {
                                    id: 'label2', 
                                    text: '<ctp:label key="imageUrl"/>', 
                                    width: '100px'
                                }, 
                                element: imageUrl,
                                colspan: 2
                        }],[                                  {
                            label: {
                                id: 'label2', 
                                text: '上传图片', 
                                width: '100px'
                            }, 
                            element: ajaxfileup,
                            colspan: 2
                    }],[                                  {
                                label: {
                                    id: 'label6', 
                                    text: '<ctp:label key="url"/>', 
                                    width: '100px'
                                }, 
                                element: url,
                                colspan: 2
                        }]                       
                	                	
                            ]
                 });

                queryGroupbox = new ctp.ui.groupbox({
                    id: 'queryGroupbox',
                    items: [
                        queryGridlayout
                    ]
                });
             
                queryForm = new ctp.form({
                    id: 'queryForm',
				    validator:formValidator,
				    width:'98%',
				    postType:'ajax',
				    fixValue:true,			        
				    ajaxPostParam:{success: formSucc} ,
                    items: [
                        queryGroupbox               
                    ],
                    buttons : [{  
	                        id: 'goBack',
	                        text:'<ctp:label key="goBack"/>',
	                        icon: 'return',
	                        onClick: goBack                     
                        },{
	                        id: 'submit',              
	                        text: '<ctp:label key="submit"/>',                  
	                        icon:'apply',
	                        onClick: submitForm 
                 		}, {                                 
	                       id: 'reset',             
	                       text: '<ctp:label key="reset"/>',                   
	                       icon:'reload',
	                       onClick:resetForm
                 	    }]	
                });

                queryPanel = new ctp.ui.panel({
                    id: 'queryPanel',
                    bodyPadding: 0,
                    collapsible:false,
                    items: [
                        queryForm
                    ]
                });

            
                borderlayout1 = new ctp.ui.borderlayout({
                    type: '1C',
                    center__size: 1.0,
                    center__items:[queryPanel],
                    renderTo: 'body'
                });
                //=========初始化页面数据===============================================
               initData();
              
            });
        </script>
    </head>
    <body>
        <ctp:form name="queryForm" method="post" action="ctpcfshomeoptionmain.flowc" flowActionName="">
        	<input type="hidden" name="filePath" value=''/>
        	<input type="hidden" name="fileName" id="fileName" value=''/>
        </ctp:form>
    </body>
</html>
